1
|
|
|
/** |
2
|
|
|
* Asynchronously save all settings in the current settings page to the database. |
3
|
|
|
* Shows an error notification if errors occur. Shows a success notification |
4
|
|
|
* otherwise. |
5
|
|
|
* |
6
|
|
|
* @param {Function} done |
7
|
|
|
*/ |
8
|
|
|
Amarkal.settings.save = function( done ) |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
Amarkal.settings._postData('save',function(res){ |
|
|
|
|
11
|
|
|
|
12
|
|
|
Amarkal.settings._clearErrors(); |
|
|
|
|
13
|
|
|
|
14
|
|
|
if(!$.isEmptyObject(res.errors)) { |
15
|
|
|
for(var name in res.errors) { |
|
|
|
|
16
|
|
|
var $comp = $('[amarkal-component-name="'+name+'"]'); |
17
|
|
|
|
18
|
|
|
$comp.amarkalUIComponent('makeInvalid'); |
19
|
|
|
$comp.parent() |
20
|
|
|
.children('.amarkal-settings-error') |
21
|
|
|
.addClass('amarkal-visible') |
22
|
|
|
.html(res.errors[name]); |
23
|
|
|
} |
24
|
|
|
Amarkal.settings.notifier.error('Some errors have occured, see below for more information.'); |
25
|
|
|
} |
26
|
|
|
else { |
27
|
|
|
Amarkal.settings.notifier.success('Settings saved', 3000); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); |
31
|
|
|
|
32
|
|
|
done(); |
33
|
|
|
}); |
34
|
|
|
}; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Asynchronously reset all settings in the current settings page to their |
38
|
|
|
* default values and erase all data from the database. Shows a success |
39
|
|
|
* notification upon completion. |
40
|
|
|
* |
41
|
|
|
* @param {Function} done |
42
|
|
|
*/ |
43
|
|
|
Amarkal.settings.resetAll = function( done ) |
44
|
|
|
{ |
45
|
|
|
Amarkal.settings._postData('reset_all',function(res){ |
|
|
|
|
46
|
|
|
|
47
|
|
|
Amarkal.settings._clearErrors(); |
|
|
|
|
48
|
|
|
Amarkal.settings.notifier.success('Default settings applied', 3000); |
49
|
|
|
$('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); |
50
|
|
|
|
51
|
|
|
done(); |
52
|
|
|
}); |
53
|
|
|
}; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Asynchronously reset all settings in the current settings section to their |
57
|
|
|
* default values and erase all section data from the database. Shows a success |
58
|
|
|
* notification upon completion. |
59
|
|
|
* |
60
|
|
|
* @param {Function} done |
61
|
|
|
*/ |
62
|
|
|
Amarkal.settings.resetSection = function( done ) |
63
|
|
|
{ |
64
|
|
|
Amarkal.settings._postData('reset_section',function(res){ |
|
|
|
|
65
|
|
|
|
66
|
|
|
Amarkal.settings._clearErrors(); |
|
|
|
|
67
|
|
|
Amarkal.settings.notifier.success('Default settings applied for the section <strong>'+Amarkal.settings.sections.getTitle(Amarkal.settings.sections.activeSection)+'</strong>', 3000); |
68
|
|
|
$('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); |
69
|
|
|
|
70
|
|
|
done(); |
71
|
|
|
}); |
72
|
|
|
}; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Reset all components and clear errors |
76
|
|
|
*/ |
77
|
|
|
Amarkal.settings._clearErrors = function() |
78
|
|
|
{ |
79
|
|
|
// Reset all components |
80
|
|
|
$('.amarkal-ui-component').amarkalUIComponent('reset'); |
81
|
|
|
$('.amarkal-settings-error').removeClass('amarkal-visible').html(''); |
82
|
|
|
}; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Send serialized form data to be processed in the backend by the function given |
86
|
|
|
* in the 'action' variable. |
87
|
|
|
* |
88
|
|
|
* @param {string} action |
89
|
|
|
* @param {Function} done |
90
|
|
|
*/ |
91
|
|
|
Amarkal.settings._postData = function( action, done ) |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
var data = $('#amarkal-settings-form').amarkalUIForm('getData'); |
94
|
|
|
$('#amarkal-settings-form').find('input[name^="_amarkal"]').each(function(){ |
95
|
|
|
data[$(this).attr('name')] = $(this).val(); |
96
|
|
|
}); |
97
|
|
|
|
98
|
|
|
// Set the active section (if applicable) |
99
|
|
|
data['_amarkal_settings_section'] = Amarkal.settings.sections.activeSection; |
|
|
|
|
100
|
|
|
|
101
|
|
|
$.post(ajaxurl, { |
|
|
|
|
102
|
|
|
action: 'amarkal_settings_'+action, |
103
|
|
|
data: data |
104
|
|
|
}, done); |
105
|
|
|
}; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.